import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { _HttpClient } from '@delon/theme';
import format from 'date-fns/format';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalRef } from 'ng-zorro-antd/modal';

@Component({
  selector: 'app-sys-loginlog-show',
  templateUrl: './show.component.html'
})
export class SysLoginlogShowComponent implements OnInit {
  record: any = {};
  i: any;
  listOfGroupOption: Array<{ label: string; value: string }> = [];
  validateForm: FormGroup;
  controlsConfig = {
    ID: [null, null],
    username: ['', []],
    info: ['', []],
    ip: ['', []],
    location: ['', []],
    create_time: ['', []]
  };

  constructor(private modal: NzModalRef, private msgSrv: NzMessageService, public http: _HttpClient, private fb: FormBuilder) {
    this.validateForm = this.fb.group(this.controlsConfig);
  }

  ngOnInit(): void {
    if (this.record.ID > 0) {
      this.http.get(`api/log/${this.record.ID}`).subscribe(res => {
        res.data.group = [res.data.group];
        res.data['create_time'] = format(new Date(res.data['create_time'] * 1000), 'yyyy-MM-dd HH:mm:ss');
        this.validateForm.patchValue(res.data);
        this.i = res.data;
      });
    }
  }

  close(): void {
    this.modal.destroy();
  }
}
